package com.qf.cloud2202.microa.controller;

import com.qf.cloud2202.vo.User;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/getall")
    public List<User> getAll() throws InterruptedException {

        TimeUnit.SECONDS.sleep(6);

        final User user1 = new User(100, "zhangsan");
        final User user2 = new User(200, "lisi");

        final List<User> users = Arrays.asList(user1, user2);
        return users;

    }


    @PostMapping("/update")
    public User update(@RequestBody User user){

        // 修改用户 信息
        System.out.println("根据用户信息修改数据库中的数据");

        user.setName("modified name");

        return user;

    }


    @DeleteMapping("/delete/{id}")
    public User delete(@PathVariable("id") Integer id){
        System.out.println("delete user by id="+id);

        final User user = new User(id,"deleted user");

        return user;
    }




}
